import pygame
from pygame import image, Rect

TILE_POSITIONS=[

    ('#',0,0),# wall   ('#',0,0),# wall
    #逗号问题
    (' ',0,1),#floor
    ('.',2,0),#dot
    ('*',3,0),#player
    ('x',1,0),#out
]

SIZE = 32


# image = 'titles.xpm'

def load_tiles():
    """
    Load tiles from an image file into a dictionary.
    Returns a tuple of (image, tile_dict)
    """
    tiles = {}
    tile_img = image.load("tiles.xpm")
    for symbol, x, y in TILE_POSITIONS:
        rect = Rect(x * SIZE, y * SIZE, SIZE, SIZE)
        tiles[symbol] = rect
    return tile_img, tiles


def get_tile_rect(x, y):
    return (x*SIZE, y*SIZE)


if __name__ == '__main__':
    tile_img, tiles = load_tiles()
    m = pygame.Surface((96, 32))
    m.blit(tile_img, get_tile_rect(0, 0), tiles['#'])
    m.blit(tile_img, get_tile_rect(1, 0), tiles[' '])
    m.blit(tile_img, get_tile_rect(2, 0), tiles['.'])
    # image.save(image.load("./images/tiles.xpm"), "t.png")
    image.save(m, 'tile_combo.png')
